Shorthand
Shorthand extension functions for validating various types.
Author
fzzyhmstrs
Since
0.2.0
Samples
import me.fzzyhmstrs.fzzy_config.FC
import me.fzzyhmstrs.fzzy_config.util.EnumTranslatable
import me.fzzyhmstrs.fzzy_config.util.Expression
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validated
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedColor
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedIds
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedList
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedRegistry
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedTag
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier
import net.minecraft.item.SwordItem
import net.minecraft.registry.Registries
import net.minecraft.registry.tag.BlockTags
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier
import java.awt.Color
import java.util.function.BiPredicate
fun main() {
//sampleStart
//shorthand validated Enum. the constant is the default value
val shorthandEnum = TestEnum.MORE.validated()
//Shorthand validated Color. The color values in the Color will be the default color components
val shorthandColor = Color(255, 255, 128, 255).validated()
//Shorthand validated Color from a base color int. The color values in the Color will be the default color components.
//In this example, the color does not accept transparency
val shorthandColorInt = 0xFF5500.validatedColor(false)
//Shorthand math Expression. This is directly in the Expression class itself, not in the Shorthand object
val shorthandMath = Expression.validated("x * 0.5", setOf('x'))
/////////////////////////////////
//example shorthand validated list. Shown is an identifier list. Note that identifier lists are actually string lists
val shorthandList = listOf(Identifier("stick")).validated(ValidatedIdentifier.ofRegistry(Identifier("stick"), Registries.ITEM))
//example Number-based shorthand list
val shorthandNumberList = listOf(1, 2, 5, 10).validated()
//example shorthand identifier list with automatic tag validation
val shorthandTagIdList = listOf(Identifier("white_bed")).validatedTag(ItemTags.BEDS)
//example shorthand identifier list with automatic registry validation
val shorthandRegistryIdList = listOf(Identifier("nether_star")).validatedRegistry(Registries.ITEM)
//example shorthand identifier list with automatic predicated registry validation
val shorthandPredicatedRegistryIdList = listOf(Identifier("stone_sword")).validatedRegistry(Registries.ITEM, BiPredicate { id, e -> e.value() is SwordItem })
//example shorthand identifier list with automatic list validation. The list should be complete and available at validation time
val shorthandListIdList = listOf(Identifier("arrow")).validatedList(listOf(Identifier("arrow"), Identifier("firework_rocket")))
//example shorthand validated Identifier using a tag for validation
val shorthandTagIds = BlockTags.AXE_MINEABLE.validatedIds()
//example shorthand validated Identifier using a registry for validation
val shorthandRegistryIds = Registries.ATTRIBUTE.validatedIds()
//example shorthand validated Identifier using a registry for validation
val shorthandPredicatedRegistryIds = Registries.ATTRIBUTE.validatedIds(BiPredicate { id, e -> id.namespace == FC.MOD_ID })
//example shorthand validated Identifier using a list for validation. The list should be complete and available at validation time
val shorthandListIds = listOf(Identifier("arrow"), Identifier("firework_rocket")).validatedIds()
//////////////////////////////////////
//example shorthand validated list. Shown is an identifier list. Note that identifier lists are actually string lists
val shorthandSet = setOf(Identifier("stick")).validated(ValidatedIdentifier.ofRegistry(Identifier("stick"), Registries.ITEM))
//example Number-based shorthand list
val shorthandNumberSet = setOf(1, 2, 5, 10).validated()
//example shorthand identifier list with automatic tag validation
val shorthandTagIdSet = setOf(Identifier("white_bed")).validatedTag(ItemTags.BEDS)
//example shorthand identifier list with automatic registry validation
val shorthandRegistryIdSet = setOf(Identifier("nether_star")).validatedRegistry(Registries.ITEM)
//example shorthand identifier list with automatic predicated registry validation
val shorthandPredicatedRegistryIdSet = setOf(Identifier("stone_sword")).validatedRegistry(Registries.ITEM, BiPredicate { id, e -> e.value() is SwordItem })
//example shorthand identifier list with automatic list validation. The list should be complete and available at validation time
val shorthandListIdSet = setOf(Identifier("arrow")).validatedList(listOf(Identifier("arrow"), Identifier("firework_rocket")))
//sampleEnd
}
Functions
Shorthand validated Enum
Shorthand validated number List
Shorthand validated number Set
Shorthand Validated TagKey, allowing any tag in the receiver tag's registry
Shorthand validated Identifier
Shorthand validated Color
Shorthand validated List
Shorthand validated Set
Shorthand validated color, based on a color int
Shorthand Validated Identifier using the List for validation
Shorthand Validated Identifier using the Registry for validation
Shorthand Validated Identifier using the TagKey for validation
Shorthand Validated Identifier using the predicated Registry for validation
Shorthand Validated Identifier List, validated with a list
Shorthand Validated Identifier Set, validated with a list
Shorthand Validated Identifier List, validated with a registry
Shorthand Validated Identifier Set, validated with a registry
Shorthand Validated Identifier List, validated with a predicated registry
Shorthand Validated Identifier Set, validated with a predicated registry
Shorthand Validated Identifier List, validated with a tag
Shorthand Validated Identifier Set, validated with a tag